﻿using System.Collections;
using UnityEngine;

//冲刺时背后产生的气团
public class EffectCloud : MyEffect
{
    private SpriteRenderer m_spriteRenderer;

    private Color defaultColor;
    [SerializeField] 
    private Color targetColor;
    private Vector3 defaultScale;
    [SerializeField] 
    private Vector3 targetScale;
    private float targetAngle = 90f;    //生命周期中要旋转的角度

    public override void OnCreate()
    {
        base.OnCreate();
        m_spriteRenderer = GetComponent<SpriteRenderer>();
        defaultColor = m_spriteRenderer.color;
        defaultScale = transform.localScale;
    }

    protected override void OnActivate()
    {
        t_exist = 1f;
        m_spriteRenderer.color = defaultColor;
        transform.localScale = defaultScale;
        base.OnActivate();
    }

    protected override IEnumerator LifeCycle()
    {
        float timer = 0f;
        float percent = 0f;
        for (; percent < 1f; timer += Time.deltaTime)
        {
            percent = timer / t_exist;
            m_spriteRenderer.color = Color.Lerp(defaultColor, targetColor, percent);
            transform.localScale = Vector3.Lerp(defaultScale, targetScale, percent);
            transform.eulerAngles = new Vector3(0f, 0f, percent * targetAngle);
            yield return null;
        }
        Recycle();
    }
}
